<?php
include('../includes/classes/core.php');
include('../includes/classes/logger.class.php');

$action	= $_REQUEST['act'];
$user_id	= $_SESSION['USERID1'];
$error	= '';
$data	= '';
$id  	= $_REQUEST['id'];

switch ($action) {
    case 'get_list':
	    $count = $_REQUEST['count'];
	    $hidden = $_REQUEST['hidden'];
	    $tab = $_REQUEST['tab'];
	    if($tab==0){
	    $rResult = mysql_query("SELECT  a_letter.id,
                                		a_letter.fact_end_date,
                                		CONCAT( '№: ბ-',`a_letter`.`id`) as latter,
                        				SUM(IF(warehouse_detail.type = 2, 0.00, b_letter_details.price)) AS price,
                        				client_objects.`name` AS client,
                        				a_letter.`comment`
                                FROM b_letter_details
                                JOIN warehouse_detail ON b_letter_details.warehouse_detail_id=warehouse_detail.id AND warehouse_detail.actived=1
                                JOIN a_letter 		  ON b_letter_details.a_letter_id = a_letter.id AND a_letter.actived =1 AND ISNULL(`a_letter`.`invoice_id`)	AND a_letter.invoice_status!=20 AND a_letter.invoice_status = 0  AND a_letter.`b_letter_status` = 1 AND	a_letter.`status` >= 4 
                                JOIN client_objects   ON client_objects.id = a_letter.client_object_id
                                JOIN client_web_users ON client_objects.client_id=client_web_users.client_id AND client_web_users.id=$user_id	
                                GROUP BY a_letter.id
                                UNION ALL
                                SELECT  d_letter.id,
                                		d_letter.fact_end_date,
                                		CONCAT( '№: ე-',`d_letter`.`id`) as latter,
                                		SUM(IF(warehouse_detail.type = 2, 0.00, e_letter_details.price)) AS price,
                                		client_objects.`name` AS client,
                                		d_letter.`comment`
                                FROM e_letter_details
                                JOIN warehouse_detail ON e_letter_details.warehouse_detail_id=warehouse_detail.id AND warehouse_detail.actived=1
                                JOIN d_letter 		  ON e_letter_details.d_letter_id = d_letter.id AND d_letter.actived =1 AND ISNULL(`d_letter`.`invoice_id`)	AND d_letter.invoice_status!=20 AND d_letter.invoice_status = 0  AND d_letter.`e_letter_status` = 1 AND	d_letter.`status` >= 4 
                                JOIN client_objects   ON client_objects.id = d_letter.client_object_id
                                JOIN client_web_users ON client_objects.client_id=client_web_users.client_id AND client_web_users.id=$user_id	
                                GROUP BY d_letter.id
	    		");
	    }elseif($tab==3){
	    	$rResult = mysql_query("
	    	    SELECT	a_letter.`id`,
                		CONCAT( '№: ბ-',`a_letter`.`id`) as latter,
                		a_letter.fact_end_date AS date,
                		SUM(IF(warehouse_detail.type = 2, 0.00, b_letter_details.price)) AS price,
                		client_objects.`name` AS client,
                		a_letter.`comment`
                FROM 	a_letter
                JOIN	client_objects ON client_objects.id = a_letter.client_object_id
                JOIN 	b_letter_details ON b_letter_details.a_letter_id=a_letter.id
                JOIN	warehouse_detail ON b_letter_details.warehouse_detail_id = warehouse_detail.id AND warehouse_detail.actived=1
                WHERE 	a_letter.actived =1 AND a_letter.invoice_id=$id
                GROUP BY 	a_letter.id
                UNION ALL
                SELECT 	d_letter.`id`,
                		CONCAT( '№: ე-',`d_letter`.`id`),
                		d_letter.fact_end_date,
                		SUM(IF(warehouse_detail.type = 2, 0.00, e_letter_details.price)),
                		client_objects.`name`,
                		d_letter.`comment`
                FROM 	d_letter
                JOIN 	client_objects ON client_objects.id = d_letter.client_object_id
                JOIN  	e_letter_details ON e_letter_details.d_letter_id=d_letter.id
                JOIN	warehouse_detail ON e_letter_details.warehouse_detail_id = warehouse_detail.id AND warehouse_detail.actived=1
                WHERE 	d_letter.actived =1 AND d_letter.invoice_id=$id
                GROUP BY 	d_letter.id
	    			");
	    }
	    else {
	    $rResult = mysql_query("SELECT   invoice.id,
                            			 invoice.end_date,
                            			 invoice.serial_number,
                            			 SUM(invoice_detail.tax),
                            			 invoice_status.`name`
                            FROM invoice
                            JOIN invoice_detail ON invoice.id =invoice_detail.invoice_id
                            LEFT JOIN invoice_status ON invoice_status.id=invoice.`status`
                            JOIN client_web_users ON client_web_users.id=$user_id
                            JOIN client  ON client.rs_un_id=invoice.buyer_un_id AND client.id=client_web_users.client_id
                            WHERE invoice.actived=1 AND invoice.id > 53257033
                            GROUP BY invoice_id
	    		");
	    }

		$data = array( "aaData"	=> array());

		while ( $aRow = mysql_fetch_array( $rResult ) )
		{
			$data['aaData'][] = $aRow;
		}


        break;
     case 'get_edit_page':
        	$letter_id	= $_REQUEST['id'];
        	$tab 		= $_REQUEST['tab'];
        	$inv 		= $_REQUEST['inv'];
        	if ($inv=='inv' & $tab==1){
        	$page		= GetPage('',$tab);
        	$data 		= array('page'	=> $page);
        	}
        	else{
        	$page		= GetPage( GetAletterInfo($letter_id) );
        	$data 		= array('page'	=> $page);
}

        break;
    default:
       $error = 'Action is Null';}

$data['error'] = $error;
echo json_encode($data);
function addNull($sum){
	if($sum != '' && $sum != '0'){
		$parts = explode('.', $sum);
		$sum1 ='';
		$sum1.= $parts[0];
		if( $parts[1] == ''){
			$sum1.= '.00';
		}else{
			$sum1 = $sum;
		}
		return $sum1;
	}else{
		return '0.00';
	}
}
function print1($aletter_id){
	$rsql = mysql_query("SELECT b_letter_details.barcode,
                				production.`name`,	
                				COUNT(DISTINCT part1.id) AS toneti,
                				COUNT(DISTINCT part2.id) AS barabani,
                				COUNT(DISTINCT part3.id) AS magnituri,
                				COUNT(DISTINCT part4.id) as rezini,
                				COUNT(DISTINCT part5.id) as gamwmendi,
                				COUNT(DISTINCT part6.id) as dozirebis,
                				COUNT(DISTINCT part7.id) AS chipi,
                				COUNT(DISTINCT part8.id) AS korpusi,
                				max(warehouse_detail.type),
                				SUM(IF(warehouse_detail.type=2,0.00, b_letter_details.price))
                        FROM `b_letter_details`
                        JOIN  a_letter on b_letter_details.a_letter_id=a_letter.id
                        LEFT JOIN  production ON SUBSTR(b_letter_details.barcode, 6, 4) = production.id
                        LEFT JOIN  client ON SUBSTR(b_letter_details.barcode, 2, 4) = client.id
                        JOIN  warehouse_detail ON b_letter_details.warehouse_detail_id=warehouse_detail.id AND warehouse_detail.actived=1
                        LEFT JOIN  b_letter_details part1 ON  part1.part_type_id=2  AND part1.id =b_letter_details.id
                        LEFT JOIN  b_letter_details part2 ON  part2.part_type_id=3  AND part2.id =b_letter_details.id
                        LEFT JOIN  b_letter_details part3 ON  part3.part_type_id=4  AND part3.id =b_letter_details.id
                        LEFT JOIN  b_letter_details part4 ON  part4.part_type_id=5  AND part4.id =b_letter_details.id
                        LEFT JOIN  b_letter_details part5 ON  part5.part_type_id=6  AND part5.id =b_letter_details.id
                        LEFT JOIN  b_letter_details part6 ON  part6.part_type_id=7  AND part6.id =b_letter_details.id
                        LEFT JOIN  b_letter_details part7 ON  part7.part_type_id=8  AND part7.id =b_letter_details.id
                        LEFT JOIN  b_letter_details part8 ON  part8.part_type_id=9  AND part8.id =b_letter_details.id
                        LEFT JOIN  b_letter_details part9 ON  part9.part_type_id=16 AND part9.id =b_letter_details.id
                        WHERE      b_letter_details.a_letter_id=$aletter_id
                        GROUP BY b_letter_details.barcode");
			GLOBAL $sum;
			while ( $aRow = mysql_fetch_array( $rsql ) ){
			$data .= '<tr style="background-color: #D9D9D9;border:1px solid black !important;">';
					for ( $i = 0 ; $i < 12 ; $i++ ){
					if($i< 2 || $i > 9){
					if( $i == 10){
					if( $aRow[$i] == 2 ){
					$aRow[11] = '0.00';
							$data .= '<td style="border:1px solid black !important; vertical-align: middle !important; text-align: center;"><img src="media/images/0.gif"></td>';
					}else{
					$data .= '<td style="border:1px solid black !important; vertical-align: middle !important; text-align: center;">&nbsp;</td>';
					}
					}else{
					$data .='<td style="border:1px solid black !important; vertical-align: middle !important; text-align: center;">'.$aRow[$i].'</td>';
					}

					}else{
					if($aRow[$i] == 1){
					$data .= '<td style="border:1px solid black !important; vertical-align: middle !important; text-align: center;"><img src="media/images/0.gif"></td>';
					}else{
					$data .= '<td style="border:1px solid black !important; vertical-align: middle !important; text-align: center;">&nbsp;</td>';
					}
					}
					if($i == 11){
					$sum = floatval($sum) + floatval($aRow[$i]);
					}
					}
					$data .= '</tr>';
			}
			return $data;
}
function print2($dletter_id){
	$rsql = mysql_query("  SELECT			printer_parts_type.`name`,
                           					production.`name`,
                            				barcodes.serial_number,
                            				IF(warehouse_detail.type = 2, 0, e_letter_details.price)
                            FROM  e_letter_details
                            JOIN	warehouse_detail ON e_letter_details.warehouse_detail_id=warehouse_detail.id AND warehouse_detail.actived=1
                            JOIN	barcodes ON warehouse_detail.barcode=barcodes.`code`
                            JOIN	production ON production.id = warehouse_detail.prod_id
                            JOIN	printer_parts_type ON printer_parts_type.id = e_letter_details.part_type_id
                            WHERE		e_letter_details.d_letter_id = '$dletter_id'");
                            	GLOBAL $sum;
	$data = '';
	while ( $aRow = mysql_fetch_array( $rsql ) ){
		$data .= '<tr>';
		for ( $i = 0 ; $i < 4 ; $i++ ){
			$data .='<td  style="border:1px solid black !important; vertical-align: middle !important; text-align: center;">'.$aRow[$i].'</td>';
			if( $i == 3){
				$sum = floatval($sum) + floatval($aRow[$i]);
			}
		}
		$data .= '</tr>';
	}
	return $data;
}
function print3($aletter_id){
	$rsql = mysql_query("SELECT  `production`.`name`,
                            				 COUNT(*)
                            FROM warehouse_detail
                            JOIN warehouse	ON warehouse_detail.warehouse_id=warehouse.id
                            LEFT JOIN	`production` ON `production`.`id` = `warehouse_detail`.`prod_id`
                            WHERE warehouse.a_letter_id=$aletter_id AND warehouse_detail.actived=1
                            GROUP BY warehouse_detail.prod_id");

	$data = '';
	while ( $aRow = mysql_fetch_array( $rsql ) ){
		$data .= '<tr>';
		for ( $i = 0 ; $i < 2 ; $i++ ){
			$data .='<td  style="border:1px solid black !important; vertical-align: middle !important; text-align: center;">'.$aRow[$i].'</td>';
			if( $i == 1){
				$sum1 = floatval($sum1) + floatval($aRow[$i]);
			}
		}
		$data .= "</tr>
				";
	}
	$data .= "
	<table ><div style='text-align: right; font-size: 10pt; margin-top: 4px;'>
	<p>სულ :&nbsp;<span style='border-bottom: 1px solid #000; padding: 0 30px; margin-left: 0px;'>$sum1 &nbsp;&nbsp;ცალი</span></p>
	</div>
	</table>";
	return $data;
}
function print4($dletter_id){
	$rsql = mysql_query("SELECT  `production`.`name`,
                        				 COUNT(*)
                        FROM warehouse_detail
                        JOIN warehouse	ON warehouse_detail.warehouse_id=warehouse.id
                        LEFT JOIN	`production` ON `production`.`id` = `warehouse_detail`.`prod_id` 
                        WHERE warehouse.d_letter_id=$dletter_id AND warehouse_detail.actived=1
                        GROUP BY warehouse_detail.prod_id");

	$data = '';
	while ( $aRow = mysql_fetch_array( $rsql ) ){
		$data .= '<tr>';
		for ( $i = 0 ; $i < 2 ; $i++ ){
			$data .='<td  style="border:1px solid black !important; vertical-align: middle !important; text-align: center;">'.$aRow[$i].'</td>';
			if( $i == 1){
				$sum = floatval($sum1) + floatval($aRow[$i]);
			}
		}
		$data .= "</tr>
				";
	}
	$data .= "
	<table ><div style='text-align: right; font-size: 10pt; margin-top: 4px;'>
	<p>სულ :&nbsp;<span style='border-bottom: 1px solid #000; padding: 0 30px; margin-left: 0px;'>$sum1 &nbsp;&nbsp;ცალი</span></p>
	</div>
	</table>";
	return $data;
}
function print5($letter_id){
	$rsql = mysql_query("SELECT

											`barcodes`.`serial_number`,
											`production`.`name`,
											IF(ISNULL((SELECT  DISTINCT warehouse_producing.packer_id FROM warehouse_producing  WHERE warehouse_producing.warehouse_detail_id = wd.id AND NOT ISNULL(warehouse_producing.packer_id)   LIMIT 1)) ,
											IF(`wd`.`status` = 0, '<img src=\"media/images/delete1.png\">', '<img src=\"media/images/apply.png\">'),
																		'<img style=\"width: 15px; height: 15px;\" src=\"media/images/pack.png\">'
																	)
								FROM		 `warehouse_detail` AS wd
								LEFT JOIN `warehouse` ON `warehouse`.`id` = `wd`.`warehouse_id`
								LEFT JOIN	`production` ON `production`.`id` = `wd`.`prod_id`
	                                 JOIN barcodes ON barcodes.`code`=wd.barcode AND barcodes.actived=1      
                        		WHERE   warehouse.d_letter_id=$letter_id AND		wd.actived=1");
	if (mysql_num_rows($rsql)>0) { }
	else{
	    $rsql = mysql_query("SELECT
	    
	        `wd`.`barcode`,
	        `production`.`name`,
	        IF(ISNULL((SELECT  DISTINCT warehouse_producing.packer_id FROM warehouse_producing  WHERE warehouse_producing.warehouse_detail_id = wd.id AND NOT ISNULL(warehouse_producing.packer_id)   LIMIT 1)) ,
	        IF(`wd`.`status` = 0, '<img src=\"media/images/delete1.png\">', '<img src=\"media/images/apply.png\">'),
	        '<img style=\"width: 15px; height: 15px;\" src=\"media/images/pack.png\">'
	    )
	        FROM		 `warehouse_detail` AS wd
	        LEFT JOIN `warehouse` ON `warehouse`.`id` = `wd`.`warehouse_id`
	        LEFT JOIN	`production` ON `production`.`id` = `wd`.`prod_id`
	        WHERE   warehouse.a_letter_id=$letter_id AND		wd.actived=1");
	    
	}
	GLOBAL $sum;
	$data = '';
	while ( $aRow = mysql_fetch_array( $rsql ) ){
		$data .= '<tr>';
		for ( $i = 0 ; $i < 3 ; $i++ ){
			$data .='<td  style="border:1px solid black !important; vertical-align: middle !important; text-align: center;">'.$aRow[$i].'</td>';
		}
		$data .= '</tr>';
	}
	return $data;
}

function GetAletterInfo($letter_id){
	$res = mysql_fetch_assoc(mysql_query("SELECT	`a_letter`.`id` as `id`,
			`a_letter`.`start_date` as `date`,
			CONCAT(`client`.`name`,'(',`client_objects`.`name`, ')') AS `client`,
			`a_letter`.`comment` as `coment`
			FROM			`a_letter`
			LEFT JOIN		`client_objects` ON `a_letter`.`client_object_id` = `client_objects`.`id`
			LEFT JOIN		`client` ON `client`.`id` = `client_objects`.`client_id`
			WHERE			`a_letter`.`id` = '$letter_id'
			UNION
			SELECT	`d_letter`.`id` as `id`,
			`d_letter`.`start_date` as `date`,
			CONCAT(`client`.`name`,'(',`client_objects`.`name`, ')') AS `client`,
			`d_letter`.`comment` as `coment`
			FROM			`d_letter`
			LEFT JOIN		`client_objects` ON `d_letter`.`client_object_id` = `client_objects`.`id`
			LEFT JOIN		`client` ON `client`.`id` = `client_objects`.`client_id`
			WHERE			`d_letter`.`id` = '$letter_id'
			"));
	return $res;
}
function GetPage($res = '',$tab){
	if($tab==1){
		$data = '
		<fieldset id="fiel_bank">
	    	<legend>ბარათები</legend>
		    <div class="inner-table">
			    <div id="dt_example" class="ex_highlight_row">
			        <div id="container" class="overhead_container">
			        	<div id="button_area"></div>
			            <div id="dynamic">
								<table class="display" style="width: 900px" id="table-3">
					                    <thead>
					                        <tr id="datatable_header">
					                            <th>ID</th>
					                            <th class="min">ბარათის ნომერი</th>
					                            <th style="width: 150px">თარიღი </th>
					                            <th style="width: 150px">თანხა</th>
					                            <th style="width: 150px">ფილიალი</th>
					                            <th style="width: 150px">შენიშვნა</th>

					                        </tr>
					                    </thead>
					                    <thead>
					                        <tr class="search_header">
					                            <th class="colum_hidden">
					                            	<input type="text" name="search_id" value="ფილტრი" class="search_init" />
					                            </th>
					                            <th>
					                                <input type="text" name="search_aleter" value="ფილტრი" class="search_init" />
					                            </th>
					                            <th>
					                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
					                            </th>
					                            	                            <th>
					                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
					                            </th>
					                            	                            <th>
					                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
					                            </th>
					                            <th>
					                                <input type="text" name="search_client" value="ფილტრი" class="search_init" />
					                            </th>
					                        </tr>
					                    </thead>
										<tfoot>
					                        <tr>
					                            <th>&nbsp;</th>
					                            <th>&nbsp;</th>
					                            <th><p align="right">ჯამი:<br/>სულ ჯამი:</th>
					                            <th align="left">&nbsp;</th>
					                            <th>&nbsp;</th>
												<th>&nbsp;</th>
					                        </tr>
					                    </tfoot>
					                </table>



			            </div>
			        </div>
			    </div>
			</div>
		</fieldset>
<input type="hidden" id="inv_id" value="'.$_REQUEST['id'].'">
	    </div>
	<div class="inner-table" >


	</div>';
	} else{
	GLOBAL $sum;
	GLOBAL $sum1;
	$later='b';

	$reQ = mysql_fetch_assoc(mysql_query("
                SELECT 	IFNULL(CONCAT('ე–',`d_letter`.`id`),CONCAT('ბ–',`a_letter`.`id`))  AS id,
                				IFNULL(d_letter.request_date, a_letter.request_date)		 as start_date,
                				rs_wdsl_status.end_date as end_date,
                				IFNULL(d_letter.end_date,a_letter.end_date) as f_end_date,
                				request_sources.`name` as source,
                				CONCAT(`client`.`name`,'  (',`client_objects`.`name`, ')') AS `client`,
                				client_objects.`id` as `obj_id`,
                				IFNULL(`d_letter`.`e_letter_status`,     `a_letter`.`b_letter_status`) as `b_letter_status`,
                				IFNULL(`d_letter`.`e_letter_overhead_id`,`a_letter`.`b_letter_overhead_id`) as `overhead_id`,
                				client_object_persons.`name` as client_p,
                				persons.`name` as obj_p
                FROM			`warehouse`
                LEFT JOIN 	a_letter 				ON IFNULL(d_letter_id,a_letter_id)=a_letter.id
                LEFT JOIN 	d_letter 				ON IFNULL(d_letter_id,a_letter_id)=d_letter.id
                LEFT JOIN	client_objects 	ON IFNULL(`d_letter`.`client_object_id`,`a_letter`.`client_object_id`) = `client_objects`.`id`
                LEFT JOIN	client 					ON `client`.`id` = `client_objects`.`client_id`
                LEFT JOIN   request_sources ON request_sources.id=IFNULL(d_letter.source,a_letter.source)
				LEFT JOIN   rs_wdsl_status  ON rs_wdsl_status.id=IFNULL(d_letter.e_letter_overhead_id,a_letter.b_letter_overhead_id)	    
                LEFT JOIN   persons 				ON IFNULL(d_letter.receiver,a_letter.receiver)=persons.id
                LEFT JOIN   client_object_persons ON client_object_persons.id=IFNULL(d_letter.requester, a_letter.requester)
                WHERE			IFNULL(d_letter_id, a_letter_id) = '$res[id]'
                LIMIT 1"));

	$m="
		";

	$data = "
		<div id='dialog-form'>
				<fieldset>
					<legend>$reQ[client]</legend>
					<table width='100%'>
						<tr>
							<td>შეკვეთის N: </td>
							<td style='width: 120px;'>$res[id]</td>
							<td>შეკვეთის დრო: </td>
							<td>$reQ[start_date]</td>
							<td></td>
						</tr>
						<tr>
							<td>შეკვეთის წყარო: </td>
							<td>$reQ[source]</td>
							<td>მიტანის გეგმიური  დრო:  <br>
							            მიტანის ფაქტიური  დრო:   </td>
							<td>$reQ[f_end_date] <br> $reQ[end_date]</td>
						</tr>

				</table>
				</fieldset>
				<div style='padding: 2px;'></div>
				<fieldset>
	";
	if (substr($reQ[id],0,3)=='ე') {
		if($_REQUEST['rw']=='wr' & $_REQUEST['tab']==0){
			$data.='<table class="display dataTable" style="width: 550px !important; border:1px solid black !important;" cellpadding="0" cellspacing="0">
		<tr class="ui-widget-header" style="border:1px solid black !important; color: white !important;">
		<td style="width: 25% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>მოდელი</span></td>
		<td style="width: 20% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;">რაოდენობა</td>
		</tr>';
			$data .= print4($res['id']);
			$data .=$m;
		}elseif ($_REQUEST['rw']=='wr' & $_REQUEST['tab']==1){
			$data.='<table class="display dataTable" style="width: 550px !important; height:25px;  border:1px solid black !important;" cellpadding="0" cellspacing="0">
		<tr  class="ui-widget-header" style="border:1px solid black !important; color: white !important;">
		<td style="width: 45% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>შტრიხკოდი</span></td>
		<td style="width: 25% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>მოდელი</span></td>
		<td style="width: 20% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;">სტატუსი</td>
		</tr>';
			$data .= print5($res['id']);
					$data .=$m;
		}
		else{
		$data.='<table class="display dataTable"  style="width: 550px !important; border:1px solid black !important;" cellpadding="0" cellspacing="0">
		<tr class="ui-widget-header" style="border:1px solid black !important; color: white !important;">
		<td style="width: 45% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>სერვისი</span></td>
		<td style="width: 25% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>მოდელი</span></td>
		<td style="width: 20% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;">შტრიხკოდი</td>
		<td style="width: 10% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;">ფასი</td>
		</tr>';

		$data .= print2($res['id']);
		$data .='			<table ><div style="text-align: right; font-size: 10pt; margin-top: 4px;">
					<p>თანხა სულ :&nbsp;<span style="border-bottom: 1px solid #000; padding: 0 30px; margin-left: 0px;">' . addNull($sum) . '&nbsp;&nbsp;ლარი</span></p>
					</div>
			</table>';
		}
	}else{
		if($_REQUEST['rw']=='wr' & $_REQUEST['tab']==0){
			$data.='<table class="display dataTable" style="width: 550px" cellpadding="0" cellspacing="0">
		<thead class="ui-widget-header">
		<tr style="border:1px !important; height:25px; color: white !important;">
		<td style="width: 25% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>მოდელი</span></td>
		<td style="width: 20% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;">რაოდენობა</td>
		</tr>
		</thead>';
			$data .= print3($res['id']);
					$data .=$m;
		}elseif ($_REQUEST['rw']=='wr' & $_REQUEST['tab']==1){
			$data.='<table class="display dataTable" style="width: 550px !important; border:1px solid black !important;" cellpadding="0" cellspacing="0">
		<thead class="ui-widget-header">
		<tr  class="ui-widget-header" style="border:1px solid black !important; color: white !important;">
		<td style="width: 45% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>შტრიხკოდი</span></td>
		<td style="width: 25% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>მოდელი</span></td>
		<td style="width: 20% !important; font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;">სტატუსი</td>
		</tr>
		</thead>'	;
			$data .= print5($res['id']);
					$data .=$m;
		}
		else{
	$data.='
					<table  style="width: 550px !important; border:1px solid black !important;" cellpadding="0" cellspacing="0">
						<tr style="background-color: #D9D9D9;border:1px solid black !important;">
							<td style="background-color: #D9D9D9; font-size: 100%  !important; border:1px solid black !important;">&nbsp;</td>
							<td style="background-color: #D9D9D9; font-size: 100%  !important; border:1px solid black !important;">&nbsp;</td>
							<td colspan="9"  style="background-color: #D9D9D9; font-size: 100%  !important; border:1px solid black !important; text-align: center;">ჩატარებული სამუშაოები</td>
							<td style="background-color: #D9D9D9; font-size: 100%  !important; border:1px solid black !important;">&nbsp;</td>
						</tr>
						<tr style="background-color: #D9D9D9;!important; border:1px solid black !important;">
							<td style="width: 170px;font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>შტრიხკოდი</span></td>
							<td style="width: 110px;font-size: 9pt; border:1px solid black !important; vertical-align: middle !important; text-align: center;"><span>მოდელი</span></td>
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">ტონერი</span></td>
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">ბარაბანი</span></td>
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">მაგნიტ. ლილ.</span></td>
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">რეზინის PCR</span></td>
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">გამწ. რაკელი</span></td>
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">დოზ. რაკელი</span></td>
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">ჩიპი</span></td>
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">კორპუსი</span></td>
							<td style="width: 25px !important; border:1px solid black !important;"><span style="writing-mode: tb-rl; -webkit-transform: rotate(270deg);	white-space: nowrap; display: block;width: 8px;	margin-top: 80px; margin-left: 4px;">საგარანტიო</span></td>
							<td style="font-size: 100%  !important; width: 110px !important; vertical-align: middle !important; text-align: center;">&nbsp;ფასი&nbsp;</td>
						</tr>';


	$data .= print1($res['id']);
	$data .='</table>
						<table ><div style="text-align: right; font-size: 10pt; margin-top: 4px;">
					<p>თანხა სულ :&nbsp;<span style="border-bottom: 1px solid #000; padding: 0 30px; margin-left: 0px;">' . addNull($sum) . '&nbsp;&nbsp;ლარი</span></p>
					</div>
			</table>
					';
		}
	}
	if ($reQ[overhead_id] > 0 |  $reQ[overhead_id] > 0)
	{
//	echo "dfffffffffffffffffffffffff"; return 0;
	$p=$reQ[client_p];$c= $reQ[obj_p];
	}else {$c=$reQ[client_p];$p= $reQ[obj_p]; }
	$data .= "
			</table>
		</fieldset>

			<fieldset style='margin-top: 4px;'>
			<legend></legend>
				<table width='90%'>
				<tr>
				<td>მიმწოდებელი: $c</td>
				<td></td>
				<td>მიმღები: $p</td>
				<td></td>
				</tr>
				</table>
			</fieldset>

	    </div>
	<div class='inner-table' >


	</div>";}

	return $data;
}

?>